package main

import (
	"container/list"
	"fmt"
)




type TreeNode struct {
	Val int
	Left *TreeNode
	Right *TreeNode
}

type ListNode struct {
	Val int
	Next *ListNode
}
func listOfDepth(tree *TreeNode) []*ListNode {
    ans:=[]*ListNode{}
	q:=list.New()
	if tree==nil{
		return ans
	}
	q.PushBack(tree)
    q.PushBack(nil)
	var head *ListNode=nil
	var lt 	*ListNode=nil
	flag:=1
    for q.Len() >0 {
        node:=q.Remove(q.Front())
        if node==nil{
			if head!=nil{
				ans=append(ans,head)
			}
			
			head=nil
			lt=nil
			if flag==1{
				q.PushBack(nil)
				flag=0
			}
		}else{
			flag=1
			tnode:=node.(*TreeNode)
			if head==nil{
				head=&ListNode{tnode.Val,nil}
				lt=head
			}else{
				lt.Next=&ListNode{tnode.Val,nil}
				lt=lt.Next
			}           
			if tnode.Left!=nil{
				q.PushBack(tnode.Left)
			}
			if tnode.Right!=nil{
				q.PushBack(tnode.Right)
			}
		}
    }


    return ans
}

func main(){
	q:=list.New()
	q.PushBack(&TreeNode{1,nil,nil})
	q.PushBack(&TreeNode{2,nil,nil})
	fmt.Println(q.Remove(q.Front()))
	fmt.Println(q.Front().Value)
	
}